﻿package 
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	
	/* Класс снаряда */
	public class ClMissle extends ClObject
	{
		public var HostObject:ClObject;
				
		public function ClMissle(host:ClObject)
		{
			super(host.stageRef);
			HostObject = host;
			
			if (Main.useEmbededContent)
				LoadEmbededImage(Assets.LaserRedImage);
			else
				LoadImage("../content/images/laser_red.png");
		}
		
		/* Вызывается после загрузки картинки */
		protected override function InitParams():void
		{
			var hostSpeed:int = Math.abs(Math.round(HostObject.ySpeed));
			if (speedPower<hostSpeed) 
				speedPower = hostSpeed;
			HostObject = null;
			hp = 1;
		}
				
		/* Апдейт */
		protected override function update(e:Event):void
		{
			y -= speedPower;
			x += xSpeed;
			if (y<-10)
				removeSelf();
			
			for (var i:int = 0; i < ClEnemy.EnemyArray.length; i++)
			{
				if (tarArea.hitTestObject(ClEnemy.EnemyArray[i].tarArea)) 
				{
					ClEnemy.EnemyArray[i].TakeHit();
					removeSelf();
				}
			}
			
			for (var i:int = 0; i < ClMeteor.MeteorArray.length; i++)
			{
				if (tarArea.hitTestObject(ClMeteor.MeteorArray[i].tarArea)) 
				{
					ClMeteor.MeteorArray[i].TakeHit(this);
					removeSelf();
				}
			}
		}
		
		
	}
}